{if isset($fields) && !empty($fields)}
{if !$options.mode.readonly}
{js include="form::iMask form::ajax form::tidy ui::helper-html"}
{/if}
{assign var=fid value=$options.name|default:0}
{if $options.file}{js include="form::aim"}{/if}

<form action="{capture assign=act}{$options.action|default:'./'}{/capture}{if $options.mode.noajax}{$act|replace:'/ajax/':'/'}{else}{$act}{/if}" method="{$options.method|default:'POST'|strtolower}" id="{$fid}" {if !$options.mode.noajax && isset($options.target)}target="{$options.target}"{/if} class="{capture assign=cls}{$options.class|default:'ajax'}{/capture}{if !$options.mode.noajax}{$cls}{else}{$cls|replace:'ajax':''}{/if}" enctype="{$options.enctype|default:'application/x-www-form-urlencoded'}" {if !$options.mode.noajax && $options.file}onsubmit="javascript:return AIM.submit(this, {ldelim}'onStart':window.startCallback,'onComplete':window.completeCallback{rdelim});"{/if}>
{if $options.file}
<input type="hidden" name="file" value="upload" />
{/if}

{assign var=hiddenfields value=""}
<table class="form-class"><tbody>
{foreach from=$fields key=k item=i}
{assign var=kid value=$k|replace:'[':''|replace:']':''}
{if isset($i.type) && $i.type=='hidden'}
{capture assign=hiddenfields}{$hiddenfields}<input name="{$k}" type="hidden" value="{$i.value.0|escape}" />{/capture}
{elseif isset($i.type)}


{if $i.type=='header'}
<tr class="header {$i.class|default:''}">{if isset($i.label)}<th colspan="2">{$i.label|default:$k|translate}</th>{else}<td colspan="2"><hr/></td>{/if}<td>&nbsp;</td></tr>
{else}
<tr class="{$i.type} {$i.class}">
{if $i.type=='check'}<th>&nbsp;</th>{else}<th><label for="form{$fid}_{$kid}">{$i.label|default:$k|translate} {if @$i.required}<a style="color:red" title="required">*</a>{/if}</label></th>{/if}
<td>
{*{if !$i.multiple&&$i.type!='static'}<input name="{$k}" type="hidden" value="" />{/if}*}
<div id="form{$fid}_{$kid}_container">
{assign var=oi value=$i}
{php}$this->_tpl_vars['oiv'] = (array)(_::pick(@$this->_tpl_vars['i']['value'],''));{/php}
{foreach from=$oiv item=i_value}
{if $i.type=='static'}
<span id="form{$fid}_{$kid}" class="{$i.class|default:''}">{$i_value} &nbsp;</span>
{elseif $i.type=='text'}
<textarea id="form{$fid}_{$kid}" name="{$k}" class="field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if}>{$i_value|default:''|escape}</textarea>
{if $options.html || $i.html}<a class="js-button js-html-helper">Show HTML Cheatsheet</a> <a class="js-button js-tidy">Do HTML Tidy</a>{/if}
{elseif $i.type=='typeable'}
{if $i.multiple}{assign var=selectName value=$k|replace:'[]':'[type][]'}{assign var=inputName value=$k|replace:'[]':'[value][]'}
{else}			{assign var=selectName value=$k|cat:'[type]'}{assign var=inputName value=$k|cat:'[value]'}{/if}
<select id="form{$fid}_{$kid}_type" name="{$selectName}" class="field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}disabled=""{/if}>
{if isset($i.null) && $i.null}<option value="0" title="&mdash;">&mdash;</option>{/if}
{foreach from=$i.types item=ti key=tk}
<option {if isset($i_value) && $i_value.type==$ti.id}selected="selected"{/if} value="{$ti.id}" title="{$ti.title|default:''|escape}">{$ti.title|default:''}</option>
{/foreach}
</select>

<input id="form{$fid}_{$kid}_value" name="{$inputName}" type="text" class="{if isset($i.mask)}iMask{/if} field-type-{$i.type} {if @$i.required}required{/if} {if isset($i.fixedLength)}fixedLength:{$i.fixedLength}{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value.value|default:''|escape}" {if isset($i.mask)}alt="{ldelim}'type':'fixed','mask':'{$i.mask|escape}','stripMask':true{rdelim}"{/if} autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

{elseif $i.type=='list'}
<select id="form{$fid}_{$kid}" name="{$k}" class="field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}disabled=""{/if}>
{if isset($i.null) && $i.null}<option value="0" title="&mdash;">&mdash;</option>{/if}
{foreach from=$i.values item=vi key=vk}
<option {if isset($i_value) && $i_value==$vi.id}selected="selected"{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}">{$vi.title|default:''}</option>
{/foreach}
</select>

{elseif $i.type=='radio'}
{if isset($i.null) && $i.null}<input type="radio" id="form{$fid}_{$kid}_null" name="{$kid}" value="" class="field-type-{$i.type} {if @$i.required}required{/if}" title="&mdash;" {if !isset($i_value)||$i_value===''}checked="checked"{elseif @$i.readonly||@$options.mode.readonly}disabled=""{/if} /><label>&mdash;</label>{if !$i.nobr}<br/>{/if}{/if}
{foreach from=$i.values item=vi key=vk}
<input type="radio" id="form{$fid}_{$kid}_{$vk}" name="{$kid}" value="{$vi.id}" {if isset($i_value) && $i_value==$vi.id}checked="checked"{elseif @$i.readonly||@$options.mode.readonly}disabled=""{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}" /><label for="form{$fid}_{$kid}_{$vk}">{$vi.title|default:''}</label>{if !$i.nobr}<br/>{/if}
{/foreach}

{elseif $i.type=='check'}
<input name="{$k}" type="hidden" value="0" />
<input id="form{$fid}_{$kid}" name="{$k}" type="checkbox" class="validate-{$i.type} {if @$i.required}required{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="1" {if $i_value>0}checked="checked"{/if} autocomplete="off" />
<label for="form{$fid}_{$kid}">{$i.label|default:$k} field-type-{$i.type} {if @$i.required}<a class="required" title="required">*</a>{/if}</label>

{elseif $i.type=='file'}
<input id="form{$fid}_{$kid}" name="{$k}" type="file" class="validate-{$i.type} {if @$i.required}required{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="" />
{if $i_value}
{if (strpos( 'jpg,jpeg,png,gif', trim(substr($i_value,-4,4),' .') )!==false)}
<img src="{$i_value}" style="float:right;border:1px solid #777;padding:5px;margin:5px;" alt="{$i_value|escape}" title="{$i_value|escape}" />
{else}
<a href="{$i_value}" target="_blank">download [{$i_value}, {$i_value}]</a>
{/if}
{/if}
{elseif $i.type=='captcha'}
{if @$i.readonly||@$options.mode.readonly}—{else}{php}echo recaptcha::getHtml();{/php}{/if}
{elseif $i.type=='money'}
<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'number','groupSymbol':',','groupDigits':3,'decSymbol':'.','decDigits':2,'stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{elseif $i.type=='date' || $i.type=='time'}
<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:{if $i.type=='date'}'%d.%m.%Y'{else}'%H:%M'{/if}" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'fixed','mask':{if $i.type=='date'}'99.99.9999'{else}'99:99'{/if},'stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{elseif $i.type=='month'}
<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:'%m.%Y'" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'99.9999','stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{elseif $i.type=='email'}
<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{elseif $i.type=='phone'}
<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|trim:'+'|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'+9 999 999-9999','stripMask':true{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{else}
{capture assign=type}{if $i.type=='string'}text{else}{$i.type}{/if}{/capture}
<input id="form{$fid}_{$kid}" name="{$k}" type="{$type}" class="{if isset($i.mask)}iMask{/if} field-type-{$i.type} {if @$i.required}required{/if} {if isset($i.fixedLength)}fixedLength:{$i.fixedLength}{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" {if isset($i.mask)}alt="{ldelim}'type':'fixed','mask':'{$i.mask|escape}','stripMask':true{rdelim}"{/if} autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
{/if}
{/foreach}
</div>
{if $i.multiple}
{capture assign=js_rel}{if $i.type=='typeable'}form{$fid}_{$kid}_container{else}form{$fid}_{$kid}{/if}{/capture}
<a class="js-button js-button-multiplicate" rel="{$js_rel}">{'add'|translate}</a>
<a class="js-button js-button-clean" rel="{$js_rel}">{'remove empty'|translate}</a>
{/if}
</td><td id="form{$fid}_{$kid}_info"><!-- --></td></tr>
{/if}
{/if}
{/foreach}
{if !$options.mode.readonly && !$options.mode.nosubmit}
<tr><th></th><td><input type="submit" value="{$options.submit|default:'Сохранить'|translate}" class="btn-submit" /></td></tr>
{/if}

</tbody></table>
{$hiddenfields}
</form>
{/if}

{$options|@d}